﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Media.Media3D;
using SosaAnalysisModule.Data;


namespace SosaAnalysisModule
{
    /// <summary>
    /// Interaction logic for ReplayEnviroment.xaml
    /// </summary>
    public partial class ReplayEnviroment : Window
    {
        //needed var
        private ReplayModule replayModule;
       
        //constructor
        public ReplayEnviroment(SosaData data)
        {
            InitializeComponent();
            replayModule = new ReplayModule(mainViewport, data);

        }

        //Used to rotate the camera
        public void rotateCamera(object sender, MouseEventArgs e)
        {
            //call to rotate the camera
            replayModule.controlCam(Mouse.GetPosition(mainViewport).X, Mouse.GetPosition(mainViewport).Y);
        }

        //used to zoom in using the camera
        public void zoomBoard(object sender, MouseWheelEventArgs e)
        {
            //determine whether to zoom in or out
            if (e.Delta < 0)
                replayModule.zoomOut();
            else if (e.Delta > 0)
                replayModule.zoomIn();
        }

        //used to reset the camera to the original position
        private void resetCamera(object sender, RoutedEventArgs e)
        {
            //call to reset the camera
            replayModule.resetCam();
        }

        //used to get the next step of the experiment
        private void nextBoardStep(object sender, RoutedEventArgs e)
        {
            //call to get the next peg placement
            replayModule.nextStep(infoBox);
        }

        //Used to get the previous step of the experiment
        private void previousBoardStep(object sender, RoutedEventArgs e)
        {
            //Call to get hte previous peg placement
            replayModule.prevStep(infoBox);
        }

        //Used to get the firs board step (blank board) of an experiment
        private void firstBoardStep(object sender, RoutedEventArgs e)
        {
            //Used to get the first step
            replayModule.firstStep(infoBox);
        }

        //Used to jump to the last or final step of the exepriment
        private void lastBoardStep(object sender, RoutedEventArgs e)
        {
            //Call to get the last step
            replayModule.lastStep(infoBox);
        }

        //Used to change the camera mode and move the vcamera when in fly mode
        private void keyboardDown(object sender, KeyEventArgs e)
        {
            //Keys used for changeing camera mode and controlling the camera
            if (e.Key == Key.A)
                replayModule.keyboard(Key.A);
            if (e.Key == Key.S)
                replayModule.keyboard(Key.S);
            if (e.Key == Key.D)
                replayModule.keyboard(Key.D);
            if (e.Key == Key.W)
                replayModule.keyboard(Key.W);
            if (e.Key == Key.LeftShift)
                replayModule.keyboard(Key.LeftShift);
        }

        private void winResize(object sender, SizeChangedEventArgs e)
        {
            //Resize the grid, viewport, and info box
            mainGrid.Width = window.ActualWidth;
            mainGrid.Height = window.ActualHeight;

            bord.Width = mainGrid.Width * .80;
            bord.Height = mainGrid.Height * .80;

            infoBox.Margin = new System.Windows.Thickness((bord.Width + 15), 10, 0, 0);
            infoBox.Width = (mainGrid.Width * 0.20) - 40;
            infoBox.Height = bord.Height;

            buttonGrid.Margin = new System.Windows.Thickness(10, (bord.Height + 15), 0, 0);
            buttonGrid.Width = mainGrid.Width - 35;
            buttonGrid.Height = (mainGrid.Height * 0.20) - 60;

            //Resize the buttons
            firstButton.Width = (buttonGrid.Width - 40) * 0.20;
            firstButton.Height = (buttonGrid.Height - 20);

            prevButton.Width = firstButton.Width;
            prevButton.Height = firstButton.Height;

            nextButton.Width = firstButton.Width;
            nextButton.Height = firstButton.Height;

            lastButton.Width = firstButton.Width;
            lastButton.Height = firstButton.Height;

            resButton.Width = firstButton.Width;
            resButton.Height = firstButton.Height;

            //Set the margins
            prevButton.Margin = new System.Windows.Thickness((firstButton.Width + 15), 10, 0, 0);
            nextButton.Margin = new System.Windows.Thickness((prevButton.Width + firstButton.Width + 20), 10, 0, 0);
            lastButton.Margin = new System.Windows.Thickness((nextButton.Width + prevButton.Width + firstButton.Width + 25), 10, 0, 0);
            resButton.Margin = new System.Windows.Thickness((nextButton.Width + prevButton.Width + firstButton.Width + lastButton.Width + 30), 10, 0, 0);
        }

    }
}
